package com.adtec.base.cloud.comminicate.communicate.commonlyused.controller;


import com.adtec.base.cloud.comminicate.communicate.commonlyused.service.CommonlyUsedService;
import com.adtec.base.cloud.commons.exception.AjaxResponse;
import com.adtec.base.cloud.persistence.communicate.model.CommCommonlyused;
import com.adtec.base.cloud.persistence.system.model.SysUserOrg;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;

@RestController
@RequestMapping("/commonlyused")
@Tag(name = "commonlyused", description = "常用地址")
public class CommonlyUsedController {
    @Resource
    private CommonlyUsedService commonlyUsedService;

    @PostMapping("/query")
    @Operation(description = "常用地址：查询")
    @Parameters({
            @Parameter(name = "id", description = "地址ID"),
            @Parameter(name = "webUrl", description = "网址"),
            @Parameter(name = "webName", description = "网址名称"),
            @Parameter(name = "webDesc", description = "网址描述"),
            @Parameter(name = "pageNum", description = "分页展示页数"),
            @Parameter(name = "pageSize", description = "分页每页页数"),
    })
    public IPage<CommCommonlyused> query(@RequestParam(name = "id", required = false) Long id,
                                   @RequestParam(name = "webUrl", required = false) String webUrl,
                                   @RequestParam(name = "webName", required = false) String webName,
                                   @RequestParam(name = "webDesc", required = false) String webDesc,
                                   @RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
                                   @RequestParam(name = "pageSize", defaultValue = "20") Integer pageSize) {
        return commonlyUsedService.queryCommonlyUsed(id, webUrl, webName, webDesc,
                pageNum, pageSize);
    }

    @PostMapping(value = "/add")
    @Operation(description = "常用地址：新增")
    public AjaxResponse add(@RequestBody CommCommonlyused commCommonlyused) {
        commonlyUsedService.add(commCommonlyused);
        return AjaxResponse.success("新增常用地址项成功！");
    }

    @PostMapping(value = "/delete")
    @Operation(description = "常用地址：删除")
    @Parameters({
            @Parameter(name = "id", description = "地址ID"),
    })
    public AjaxResponse delete(@RequestParam Long id) {
        commonlyUsedService.delete(id);
        return AjaxResponse.success("删除常用地址项成功!");
    }

    @PostMapping(value = "/update")
    @Operation(description = "常用地址：更新")
    public AjaxResponse update(@RequestBody CommCommonlyused commCommonlyused) {
        commonlyUsedService.update(commCommonlyused);
        return AjaxResponse.success("更新常用地址项成功！");
    }

}
